package com.nts.bupna;

import java.io.File;
import java.io.FileReader;
import java.nio.charset.Charset;

import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.nts.bupna.generator.ProcessToJava;
import com.nts.bupna.model.Process;

public class Main {

    public static void main(final String[] args) {
        try {
            final String contents = CharStreams.toString(new FileReader(args[0]));
            String parsedProcess = parseProcess(contents);
            File file = new File(args[1]);
            file.getParentFile().mkdirs();
            CharStreams.write(parsedProcess, Files.newWriterSupplier(file, Charset.forName("UTF-8")));
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }

    private static String parseProcess(final String contents) {
        final Bupna bupna = new Bupna();
        final Process process = bupna.parse(contents);
        final ProcessToJava generator = new ProcessToJava(process);
        return generator.generateJavaCode();
    }

}
